#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

struct Edge {
	int to, nxt, c;
} e[10000];
int e_cnt, n, m, dis[2600], ans, ans_pos = 0;
int dc[2600];
int heads[2600];
inline void add(int pre, int to, int c) {
	e[++e_cnt].to = to;
	e[e_cnt].c = c;
	e[e_cnt].nxt = heads[pre];
	heads[pre] = e_cnt;
}

priority_queue< pair< int, int > > q;
inline void dij(int u) {
	dis[u] = 0;
	q.push(make_pair(0, u));
	while (q.size()) {
		int x = q.top().second;
		int d = -q.top().first;
		q.pop();
		if (d != dis[x]) {
			continue;
		}
		for (int i = heads[x]; i; i = e[i].nxt) {
			int y = e[i].to;
			int z = e[i].c;
			if (dis[y] > dis[x] + z) {
				dis[y] = dis[x] + z;
				q.push(make_pair(-dis[y], y));
			}
		}
	}
}
int main() {
	freopen("testdata.in", "r", stdin);
	freopen("testdata.out", "w", stdout);
	// freopen("exciting.in", "r", stdin);
	// freopen("exciting.out", "w", stdout);
	scanf("%d%d", &n, &m);
	memset(dis, 0x7F, sizeof(dis));
	for (int i = 0; i < m; i++) {
		int tmp1, tmp2, tmp3;
		scanf("%d%d%d", &tmp1, &tmp2, &tmp3);
		add(tmp1, tmp2, tmp3);
		add(tmp2, tmp1, tmp3);
	}
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &dc[i]);
	}
	for (int i = 1; i <= n; ++i) {
		ans = 0x7fffffff;
		memset(dis,0x3f,sizeof(dis));
		dij(i);
		for (int j = 1; j <= n; ++j) {
			dis[j] *= 2;
			dis[j] += dc[j];
			if (ans > dis[j]) {
				ans = dis[j];
			}
		}
		printf("%d ", ans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}